using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbDonHangBUS
    {
        public static void Insert(tbDonHang donhang)
        {
            tbDonHangDAL dhDAL = new tbDonHangDAL();
            dhDAL.Insert(donhang);
        }
        public static void Update(tbDonHang donhang)
        {
            tbDonHangDAL dhDAl = new tbDonHangDAL();
            dhDAl.Update(donhang );
        }
        public static void Delete(int iD)
        {
            tbDonHangDAL dhDAl = new tbDonHangDAL();
            dhDAl.Delete(iD);
        }
        public static tbDonHangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbDonHangDAL dhDAL = new tbDonHangDAL();
            return dhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDonHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonHangDAL haDAL = new tbDonHangDAL();
            return haDAL.Get(cri.Criter, 0, 0, tbDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbDonHang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDonHangColumns.MaDH.ToString(), Condition.EQUAL, iD);
            tbDonHangDAL dhDAL = new tbDonHangDAL();
            tbDonHangCollection dhCollection = dhDAL.Get(cri.Criter, 0, 0, tbDonHangColumns.MaDH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dhCollection.Count > 0)
                return dhCollection[0];
            return null;
        }
        public static tbDonHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonHangDAL dhDAL = new tbDonHangDAL();
            return dhDAL.Get(cri.Criter, 1, number, tbDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDonHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDonHangDAL dhDAL = new tbDonHangDAL();
            return dhDAL.Get(cri.Criter, 1, number, tbDonHangColumns.MaDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }

        public static void UpdateTrangThai(int id)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
